package com.yango.order.controller;

import com.yango.logistics.pojo.Logistics;
import com.yango.order.pojo.Order;
import com.yango.order.properties.OrderProperties;
import com.yango.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/create")
    public Order createOrder(@RequestParam("productId") Long productId,
                             @RequestParam("userId")Long userId){
        Order order =orderService.createOrder(productId,userId);
        return order;
    }
//    @GetMapping("/logistics")
//    public Logistics getOrder(@RequestParam("orderId") Long orderId){
//        return orderService.getLogisticsById(orderId);
//    }
//    @Value("${order.timeout}")
//    private String orderTimeout;
//    @Value("${order.auto-confirm}")
//    private String orderAutoConfirm;
//    @GetMapping("/config")
//    public String getConfig(){
//        return "timeout:" + orderTimeout+"; auto - confirm"+orderAutoConfirm;
//
//    }

    @Autowired
    private OrderProperties orderProperties;
    @GetMapping("/config")
    public String getConfig(){
        return "timeout:" + orderProperties.getTimeout()+"; auto-confirm："+orderProperties.getAutoConfirm();
    }


}
